# -*- coding: utf-8 -*-

# Copyright (c) 2010 Jérémie DECOCK (http://www.jdhp.org)

class Environment:
    
    agent = None
    gui = None

    state_list = None
    action_list = None

    initial_state = None
    terminal_state_list = None

    def __init__(self, agent):
        raise NotImplementedError()

    def run(self):
        "The main loop."
        state = self.initial_state
        reward = None
        terminated = False
        
        while not terminated:
            action = self.agent.get_action(state, reward)
            former_state, state, terminated = self.execute_action(state, action)
            reward = self.reward(former_state, action, state)
            self.update_ui()

    def execute_action(self, state, action):
        raise NotImplementedError()

    def transition(self, src_state, action, dst_state):
        """Transition model.

        Return the probability to reach the state 'dst_state' if an action
        'action' is done in the state 'src_state'."""
        raise NotImplementedError()

    def reward(self, state, former_state=None, action=None):
        raise NotImplementedError()

    def update_ui(self):
        raise NotImplementedError()

